<?php

namespace App\Jobs\Zhunya;

use app\chat\LiveMessage;
use Log;

use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;

class LiveSendMsgJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    public $jobData;

    /**
     * Create a new job instance.
     *
     * @param array $jobData
     */
    public function __construct(array $jobData)
    {
        $this->jobData = $jobData;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function task()
    {
      $jobData = $this->jobData;
       //获取
        try
        {
//            LiveMessage::sendMsgNow($jobData['msg'], $jobData['who'], $jobData['msg_type'], $jobData['data'], $jobData['exclude_client_ids']);
            $job->delete();
            print('success');
        }
        catch (\Exception $e)
        {
            Log::write('队列发送直播消息 失败：' . $e->getMessage() . json_encode($jobData) . PHP_EOL . '错误行数：' . '[' . $e->getFile() . ':' . $e->getLine() . ']', 'error', true);
        }

        $jobDataLog = json_encode($jobData, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
        Log::write('队列发送直播消息 结束时间：' . date('Y-m-d H:i:s') . ' $jobDataLog=' . $jobDataLog, 'log', true);
    }
}